import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 初始化 WebDriver
driver = webdriver.Chrome()

# 打开京东首页
driver.get("https://www.jd.com")

# 等待页面加载完成
try:
    wait = WebDriverWait(driver, 10)
    # 等待页面中的某个元素加载完成，
    wait.until(EC.presence_of_element_located((By.ID, "key")))

    # 休眠 5 秒
    time.sleep(5)


    print("页面加载成功！")

except Exception as e:
    print(f"发生错误：{e}")
finally:

    driver.save_screenshot("page_loaded.png")


    driver.quit()
